package com.example.administrator.yuejian35.Club.fragment.viewholder;

import android.content.Context;
import android.net.Uri;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.administrator.yuejian35.Club.bean.Video;
import com.example.administrator.yuejian35.Home.adapter.RecyclerItemBaseHolder;
import com.example.administrator.yuejian35.Home.bean.Course;
import com.example.administrator.yuejian35.R;

import butterknife.ButterKnife;

import static com.example.administrator.yuejian35.Config.CourseImages_URL;
import static com.example.administrator.yuejian35.Config.Video_URL;

/**
 * Created by HP on 2017/9/26.
 */

public class VideoItemViewHolder1 extends RecyclerItemBaseHolder {
    public final static String TAG = "RecyclerView2List";
    protected Context context = null;
    FrameLayout listItemContainer;

    ImageView imageView;
    public  ImageView pic;
    public  TextView name;
    public  View itemView;//添加Onclick监听器

    public VideoItemViewHolder1(Context context, View v) {
        super(v);
        this.context = context;
        ButterKnife.bind(this, v);
        imageView = new ImageView(context);
        listItemContainer = (FrameLayout) v.findViewById(R.id.list_item_container);
        pic = (ImageView) v.findViewById(R.id.video_pic);
        name = (TextView) v.findViewById(R.id.video_name);

    }

    public void onBind(final int position, final Video video) {

        //增加封面
        imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
        imageView.setImageResource(R.drawable.lunbotu);
        Uri uri = Uri.parse(CourseImages_URL+video.getVideopic());
        imageView.setImageURI(uri);

        listVideoUtil.addVideoPlayer(position, imageView, TAG, listItemContainer, pic);

        pic.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                getRecyclerBaseAdapter().notifyDataSetChanged();
                //listVideoUtil.setLoop(true);
                listVideoUtil.setPlayPositionAndTag(position, TAG);
                listVideoUtil.setTitle("title " + video.getVideoname());
                String url;
                if (position % 2 == 0) {
                    url = Video_URL+"video1.mp4";
                } else {
                    url = "http://7xse1z.com1.z0.glb.clouddn.com/1491813192";
                }
                //listVideoUtil.setCachePath(new File(FileUtils.getPath()));
                listVideoUtil.startPlay(url);

                //必须在startPlay之后设置才能生效
                //listVideoUtil.getGsyVideoPlayer().getTitleTextView().setVisibility(View.VISIBLE);
            }
        });
    }

}